package io.kiki.sba.registry.common.model.store;

import io.kiki.sba.registry.common.model.ClientInterfaceId;
import io.kiki.sba.registry.common.model.RegisterVersion;


public class UnPublisher extends Publisher {


    public UnPublisher(String dataInfoId, ClientInterfaceId clientInterfaceId, String registerId, long registerTimeStamp, long version) {
        setDataInfoId(dataInfoId);
        setRegisterId(registerId);
        setRegisterTimestamp(registerTimeStamp);
        setVersion(version);
        // avoid new datum dataId is null
        DataInfo dataInfo = DataInfo.valueOf(dataInfoId);
        setDataId(dataInfo.getDataId());
        setGroup(dataInfo.getGroup());
        setInstanceId(dataInfo.getInstanceId());

        setClientInterfaceId(clientInterfaceId);
    }

    public static UnPublisher of(Publisher publisher) {
        return new UnPublisher(publisher.getDataInfoId(), publisher.getClientInterfaceId(), publisher.getRegisterId(), publisher.getRegisterTimestamp(), publisher.getVersion());
    }

    public static UnPublisher of(String dataInfoId, String registerId, RegisterVersion version) {
        return new UnPublisher(dataInfoId, null, registerId, version.getRegisterTimestamp(), version.getVersion());
    }

    @Override
    public DataType getDataType() {
        return DataType.un_publisher;
    }
}
